import pymysql

conn = None

cursor = None

try:
    conn = pymysql.connect(host='localhost',user='root',passwd='123456',db='test01',charset='utf8')

    cursor = conn.cursor()

    cursor.execute("select * from t_book;")

    res1 = cursor.fetchone()
    print("res1:",res1)
    res2 = cursor.fetchone()
    print("res2:",res2)
    cursor.rownumber = 0
    res3 = cursor.fetchmany(2)
    print("res3:",res3)
    cursor.rownumber = 3
    res4 = cursor.fetchall()
    print("res4:",res4)
    cursor.rownumber = 0
    res5 = cursor.fetchall()
    print("res5:",res5)

except Exception as e:
    print("查询结果出错:",str(e))

finally:

    cursor.close()

    conn.close()